<?php
	$id = $_POST['id_ppk'];
	$ppk = $_POST['ppk'];
	
	if(isset($_POST['submit'])){
		//Tarif ABHP
		$qry_abhp = "select * from tarif_abhp where id_ppk = $ppk";
		$qry1 = mysql_query($qry_abhp);
		while($a = mysql_fetch_array($qry1)){
			$cek = mysql_query("select id_tarif from tarif_abhp where id_ppk = $id and id_abhp = '$a[id_abhp]'");
			$jml = mysql_num_rows($cek);
			if($jml > 0){
				mysql_query("update tarif_abhp set tarif = $a[tarif] where id_ppk = $id and id_abhp = '$a[id_abhp]'");
			}else{
				mysql_query("insert into tarif_abhp(id_ppk,id_abhp,tarif) values ($id,'$a[id_abhp]',$a[tarif])");
			}
		}
		
		//Tarif Obat
		$qry_obat = "select * from tarif_obat where id_ppk = $ppk";
		$qry2 = mysql_query($qry_obat);
		while($o = mysql_fetch_array($qry2)){
			$cek = mysql_query("select id_tarif from tarif_obat where id_ppk = $id and id_obat = '$o[id_obat]'");
			$jml = mysql_num_rows($cek);
			if($jml > 0){
				mysql_query("update tarif_obat set tarif = $o[tarif] where id_ppk = $id and id_obat = '$o[id_obat]'");
			}else{
				mysql_query("insert into tarif_obat(id_ppk,id_obat,tarif) values ($id,'$o[id_obat]',$o[tarif])");
			}
		}
		
		//Tarif Layanan
		$qry_layanan = "select * from tarif_layanan where id_ppk = $ppk";
		$qry3 = mysql_query($qry_layanan);
		while($l = mysql_fetch_array($qry3)){
			$cek = mysql_query("select id_tarif from tarif_layanan where id_ppk = $id and id_layanan = '$l[id_layanan]'");
			$jml = mysql_num_rows($cek);
			if($jml > 0){
				mysql_query("update tarif_layanan set tarif = $l[tarif] where id_ppk = $id and id_layanan = '$l[id_layanan]'");
			}else{
				mysql_query("insert into tarif_layanan(id_ppk, id_layanan, tarif) values ($id,'$l[id_layanan]',$l[tarif])");
			}
		}
		
		//Tarif Tindakan
		$qry_tindakan = "select * from tarif_tindakan where id_ppk = $ppk";
		$qry4 = mysql_query($qry_tindakan);
		while($t = mysql_fetch_array($qry4)){
			$cek = mysql_query("select id_tarif from tarif_tindakan where id_ppk = $id and id_tindakan = '$t[id_tindakan]'");
			$jml = mysql_num_rows($cek);
			if($jml > 0){
				mysql_query("update tarif_tindakan set tarif = $t[tarif] where id_ppk = $id and id_tindakan = '$t[id_tindakan]'");
			}else{
				mysql_query("insert into tarif_tindakan(id_ppk, id_tindakan, tarif) values ($id,'$t[id_tindakan]',$t[tarif])");
			}
		}
		
		//Tarif Laboratorium
		$qry_lab = "select * from tarif_laboratorium where id_ppk = $ppk";
		$qry5 = mysql_query($qry_lab);
		while($t = mysql_fetch_array($qry5)){
			$cek = mysql_query("select id_tarif from tarif_laboratorium where id_ppk = $id and id_lab = $t[id_lab]");
			$jml = mysql_num_rows($cek);
			if($jml > 0){
				mysql_query("update tarif_laboratorium set tarif = $t[tarif] where id_ppk = $id and id_lab = $t[id_lab]");
			}else{
				mysql_query("insert into tarif_laboratorium(id_ppk, id_lab, tarif) values ($id,$t[id_lab],$t[tarif])");
			}
		}
		
		//Tarif Radiologi
		$qry_radiologi = "select * from tarif_radiologi where id_ppk = $ppk";
		$qry6 = mysql_query($qry_radiologi);
		while($t = mysql_fetch_array($qry6)){
			$cek = mysql_query("select id_tarif from tarif_radiologi where id_ppk = $id and id_radiologi = $t[id_radiologi]");
			$jml = mysql_num_rows($cek);
			if($jml > 0){
				mysql_query("update tarif_radiologi set tarif = $t[tarif] where id_ppk = $id and id_radiologi = $t[id_radiologi]");
			}else{
				mysql_query("insert into tarif_radiologi(id_ppk, id_radiologi, tarif) values ($id,$t[id_radiologi],$t[tarif])");
			}
		}
	}
	$url_sukses='utama.php?module=mod_ppk';
	if($qry){
		echo "<meta http-equiv='refresh' content='0; url=$url_sukses'>";
		exit;
	}else{
		echo mysql_error();
	}
?>